package com.wc.alorithm_luogu.P5736;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/4/24 10:39
 * @description https://www.luogu.com.cn/problem/P5736
 * 质数筛
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        List<Integer> ans = new ArrayList<>();

        int n = sc.nextInt();
        int num = 0;
        while (n-- > 0) {
            num = sc.nextInt();
            if (isPrime(num)) {
                ans.add(num);
            }
        }
        if (ans.size()==0){
            return;
        }
        System.out.print(ans.get(0));
        int size = ans.size();
        for (int i = 1; i < size; i++) {
            System.out.print(" " + ans.get(i));
        }
    }

    public static boolean isPrime(int num) {
        if (num <= 1) {
            return false;
        }

        int mid = (int) Math.pow(num, 0.5);
        for (int i = 2; i <= mid; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
